#ifndef _WX_AUITABMDI_H_
#define _WX_AUITABMDI_H_

#include "wx/frame.h"
#include "wx/panel.h"
#include "wx/notebook.h"
#include "wx/icon.h"
#include "wx/aui/auibook.h"

class wxAuiMDIParentFrame;
class wxAuiMDIClientWindow;
class wxAuiMDIChildFrame;

class wxAuiMDIParentFrame : public wxFrame {
  public:
    wxAuiMDIParentFrame();
    wxAuiMDIParentFrame( wxWindow *parent,wxWindowID winid,
                         const wxString& title,
                         const wxPoint& pos = wxDefaultPosition,
                         const wxSize& size = wxDefaultSize,
                         long style = wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL,
                         const wxString& name = wxFrameNameStr );

    ~wxAuiMDIParentFrame();

    bool Create( wxWindow *parent,
                 wxWindowID winid,
                 const wxString& title,
                 const wxPoint& pos = wxDefaultPosition,
                 const wxSize& size = wxDefaultSize,
                 long style = wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL,
                 const wxString& name = wxFrameNameStr );

    void SetArtProvider( wxAuiTabArt* provider );
    wxAuiTabArt* GetArtProvider();
    wxAuiNotebook* GetNotebook() const;
    wxMenu* GetWindowMenu() const { return m_pWindowMenu; }
    void SetWindowMenu( wxMenu* pMenu );
    virtual void SetMenuBar( wxMenuBar *pMenuBar );
    void SetChildMenuBar( wxAuiMDIChildFrame *pChild );
    virtual bool ProcessEvent( wxEvent& event );
    wxAuiMDIChildFrame *GetActiveChild() const;
    void SetActiveChild( wxAuiMDIChildFrame* pChildFrame );
    wxAuiMDIClientWindow *GetClientWindow() const;
    virtual wxAuiMDIClientWindow *OnCreateClient();

    virtual void Cascade() { /* Has no effect */ }
    virtual void Tile( wxOrientation orient = wxHORIZONTAL );
    virtual void ArrangeIcons() { /* Has no effect */ }
    virtual void ActivateNext();
    virtual void ActivatePrevious();

  protected:
    wxAuiMDIClientWindow*   m_pClientWindow;
    wxAuiMDIChildFrame*     m_pActiveChild;
    wxEvent*                m_pLastEvt;
    wxMenu              *m_pWindowMenu;
    wxMenuBar           *m_pMyMenuBar;

  protected:
    void Init();
    void RemoveWindowMenu( wxMenuBar *pMenuBar );
    void AddWindowMenu( wxMenuBar *pMenuBar );
    void DoHandleMenu( wxCommandEvent &event );
    virtual void DoGetClientSize( int *width, int *height ) const;
  private:
    DECLARE_EVENT_TABLE()
    DECLARE_DYNAMIC_CLASS( wxAuiMDIParentFrame )
};

class wxAuiMDIChildFrame : public wxPanel {
  public:
    wxAuiMDIChildFrame();
    wxAuiMDIChildFrame( wxAuiMDIParentFrame *parent,
                        wxWindowID winid,
                        const wxString& title,
                        const wxPoint& pos = wxDefaultPosition,
                        const wxSize& size = wxDefaultSize,
                        long style = wxDEFAULT_FRAME_STYLE,
                        const wxString& name = wxFrameNameStr );

    virtual ~wxAuiMDIChildFrame();
    bool Create( wxAuiMDIParentFrame *parent,
                 wxWindowID winid,
                 const wxString& title,
                 const wxPoint& pos = wxDefaultPosition,
                 const wxSize& size = wxDefaultSize,
                 long style = wxDEFAULT_FRAME_STYLE,
                 const wxString& name = wxFrameNameStr );

    virtual void SetMenuBar( wxMenuBar *menu_bar );
    virtual wxMenuBar *GetMenuBar() const;
    virtual void SetTitle( const wxString& title );
    virtual wxString GetTitle() const;

    virtual void SetIcons( const wxIconBundle& icons );
    virtual const wxIconBundle& GetIcons() const;

    virtual void SetIcon( const wxIcon& icon );
    virtual const wxIcon& GetIcon() const;

    virtual void Activate();
    virtual bool Destroy();

    #if wxUSE_STATUSBAR
    // no status bars
    virtual wxStatusBar* CreateStatusBar( int ( number ) = 1,
                                          long ( style ) = 1,
                                          wxWindowID ( winid ) = 1,
                                          const wxString& ( name ) = wxEmptyString ) { return ( wxStatusBar* )NULL; }

    virtual wxStatusBar *GetStatusBar() const { return ( wxStatusBar* )NULL; }
    virtual void SetStatusText( const wxString &( text ), int ( number ) = 0 ) {}
    virtual void SetStatusWidths( int ( n ), const int ( widths_field )[] ) {}
    #endif

    // no size hints
    virtual void DoSetSizeHints( int ( minW ),
                                 int ( minH ),
                                 int ( maxW ) = wxDefaultCoord,
                                 int ( maxH ) = wxDefaultCoord,
                                 int ( incW ) = wxDefaultCoord,
                                 int ( incH ) = wxDefaultCoord ) {}
    #if wxUSE_TOOLBAR
    // no toolbar bars
    virtual wxToolBar* CreateToolBar( long ( style ),
                                      wxWindowID ( winid ),
                                      const wxString& ( name ) ) { return ( wxToolBar* )NULL; }
    virtual wxToolBar *GetToolBar() const { return ( wxToolBar* )NULL; }
    #endif


    // no maximize etc
    virtual void Maximize( bool ( maximize ) = true ) { /* Has no effect */ }
    virtual void Restore() { /* Has no effect */ }
    virtual void Iconize( bool ( iconize )  = true ) { /* Has no effect */ }
    virtual bool IsMaximized() const { return true; }
    virtual bool IsIconized() const { return false; }
    virtual bool ShowFullScreen( bool ( show ), long ( style ) ) { return false; }
    virtual bool IsFullScreen() const { return false; }

    virtual bool IsTopLevel() const { return false; }

    void OnMenuHighlight( wxMenuEvent& evt );
    void OnActivate( wxActivateEvent& evt );
    void OnCloseWindow( wxCloseEvent& evt );

    void SetMDIParentFrame( wxAuiMDIParentFrame* parent );
    wxAuiMDIParentFrame* GetMDIParentFrame() const;

  protected:
    void Init();
    virtual bool Show( bool show = true );
    virtual void DoSetSize( int x, int y, int width, int height, int size_flags );
    virtual void DoMoveWindow( int x, int y, int width, int height );

  public:
    void ApplyMDIChildFrameRect();
    void DoShow( bool show );

  protected:
    wxAuiMDIParentFrame* m_pMDIParentFrame;
    wxRect m_mdi_newrect;
    wxRect m_mdi_currect;
    wxString m_title;
    wxIcon m_icon;
    wxIconBundle m_icon_bundle;
    bool m_activate_on_create;
    wxMenuBar* m_pMenuBar;
  private:
    DECLARE_DYNAMIC_CLASS( wxAuiMDIChildFrame )
    DECLARE_EVENT_TABLE()

    friend class wxAuiMDIClientWindow;
};

class wxAuiMDIClientWindow : public wxAuiNotebook {
  public:
    wxAuiMDIClientWindow();
    wxAuiMDIClientWindow( wxAuiMDIParentFrame *parent, long style = 0 );
    ~wxAuiMDIClientWindow();

    virtual bool CreateClient( wxAuiMDIParentFrame *parent,long style = wxVSCROLL | wxHSCROLL );

    virtual int SetSelection( size_t page );

  protected:

    void PageChanged( int old_selection, int new_selection );
    void OnPageClose( wxAuiNotebookEvent& evt );
    void OnPageChanged( wxAuiNotebookEvent& evt );
    void OnSize( wxSizeEvent& evt );

  private:
    DECLARE_DYNAMIC_CLASS( wxAuiMDIClientWindow )
    DECLARE_EVENT_TABLE()
};

#endif // _WX_AUITABMDI_H_
